﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// PaperAnswerOption业务逻辑简要说明。
    /// </summary>
    public class PaperAnswerOption
    {
        /// <summary>
        /// 组织机构DAL
        /// </summary>
        private readonly DAL.PaperAnswerOption dal = new DAL.PaperAnswerOption();
        /// <summary>
        /// 构造函数
        /// </summary>
        public PaperAnswerOption()
        { }
        /// <summary>
        /// 获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// </summary>
        /// <param name="strWhere">查询条件</param>
        /// <returns>DataTableToList表</returns>
        public List<Model.PaperAnswerOption> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetModelList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// </summary>
        /// <param name="dt">DataTable表</param>
        /// <returns>List集合</returns>
        public List<Model.PaperAnswerOption> DataTableToList(DataTable dt)
        {
            List<Model.PaperAnswerOption> modelList = new List<Model.PaperAnswerOption>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.PaperAnswerOption model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.PaperAnswerOption();
                    if (dt.Rows[n]["FPaperTopicId"] != null && dt.Rows[n]["FPaperTopicId"].ToString() != "")
                    {
                        model.FPaperTopicId = decimal.Parse(dt.Rows[n]["FPaperTopicId"].ToString());
                    }
                    if (dt.Rows[n]["FAnswerNo"] != null && dt.Rows[n]["FAnswerNo"].ToString() != "")
                    {
                        model.FAnswerNo = dt.Rows[n]["FAnswerNo"].ToString();
                    }
                    if (dt.Rows[n]["FAnswerContent"] != null && dt.Rows[n]["FAnswerContent"].ToString() != "")
                    {
                        model.FAnswerContent = dt.Rows[n]["FAnswerContent"].ToString();
                    }
                    if (dt.Rows[n]["FIsRestsAnswer"] != null && dt.Rows[n]["FIsRestsAnswer"].ToString() != "")
                    {
                        model.FIsRestsAnswer = dt.Rows[n]["FIsRestsAnswer"].ToString();
                    }
                    if (dt.Rows[n]["FRestsAnswerCount"] != null && dt.Rows[n]["FRestsAnswerCount"].ToString() != "")
                    {
                        model.FRestsAnswerCount = int.Parse(dt.Rows[n]["FRestsAnswerCount"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 删除选择项并且修改该选择项后面的所有选择项的编号 事务模式
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="topicId">主题编号</param>
        /// <param name="answerNo">答案</param>
        /// <param name="updAnswerOptionList">答案的集合</param>
        public void DelAndUpdAnswerNo(decimal topicId, string answerNo, List<Model.PaperAnswerOption> updAnswerOptionList)
        {
            dal.DelAndUpdAnswerNo(topicId, answerNo, updAnswerOptionList);
        }


    }
}
